import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import store from '@/store'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: "/home"
  },
  {
    path: '/home',
    name: 'Home',
    component: Home
  },
  // {
  //   path: '/about',
  //   name: 'About',
  //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  // }
  {
    path: '/goods',
    component: () => import(/* webpackChunkName: "goods" */ '../views/Goods.vue')
  },
  {
    path: '/user',
    redirect:"/user/profiles",
    component: () => import(/* webpackChunkName: "user" */ '../views/User.vue'),
    children:[
      {
        // path: '/user/cart',
        path: 'cart',
        component: () => import(/* webpackChunkName: "cart" */ '../components/user/Cart.vue')
      },
      {
        // path: '/user/cart',
        path: 'profiles',
        component: () => import(/* webpackChunkName: "cart" */ '../components/user/Profiles.vue')
      },
    ]
  },
  {
    path: '/order',
    component: () => import(/* webpackChunkName: "order" */ '../views/Order.vue')
  },
  {
    path: '/free',
    component: () => import(/* webpackChunkName: "goods" */ '../views/Free.vue')
  },
  {
    path: '/details',
    component: () => import(/* webpackChunkName: "details" */ '../views/Details.vue')
  },
  {
    path: '*',
    name:"Error",
    component: () => import(/* webpackChunkName: "error" */ '../views/Error.vue')
  },
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})
//全局导航守卫
// router.beforeEach((to, from, next) => {
//   //to 要去到那个路由
//   //from 从那个路由发生跳转
//   //没有登录的时候不能进入个人中心
//   if (to.path == "/user") {
//     let token = localStorage.getItem("x-auth-token");
//     if (token) {
//       next()
//     } else {
//       store.dispatch("showToast/asyncChanIsShowToast", {
//         msg: "你还没有登录ya！",
//         type: "warning",

//       })
//     return
//     }

//     }
//     next()
//   })


export default router
